package org.example.elmfront.mapper;
import org.apache.ibatis.annotations.*;
import org.example.elmfront.entity.OrderItem;
import java.util.List;

@Mapper
public interface OrderItemMapper {

    @Insert("INSERT INTO order_items (order_id, product_id, quantity, price, added_at) " +
            "VALUES (#{order.id}, #{product.id}, #{quantity}, #{price}, #{addedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertOrderItem(OrderItem orderItem);

    @Delete("DELETE FROM order_items WHERE id = #{id}")
    void deleteOrderItemById(Integer id);

    @Update("UPDATE order_items SET quantity = #{quantity}, price = #{price}, added_at = #{addedAt} " +
            "WHERE id = #{id}")
    void updateOrderItem(OrderItem orderItem);

    @Select("SELECT * FROM order_items WHERE order_id = #{orderId}")
    List<OrderItem> findOrderItemsByOrderId(Long orderId);

    @Select("SELECT * FROM order_items WHERE id = #{id}")
    OrderItem findOrderItemById(Integer id);
}

